package com.uenpay.im.zxing;

import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;
import com.uenpay.im.invokeitems.BaseHttpInvokeItem;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * @author SL
 * @E-mail:
 * @date 创建时间：2016-7-11 下午5:11:54
 * @version 1.0
 * @parameter
 * @Function TODO
 */
public class CaptureInvokeItem extends BaseHttpInvokeItem {

	public class CaptureInvokeItemResult extends HttpInvokeResult {
		public String controller;
		public JSONObject body;
	}

	public CaptureInvokeItemResult getOutPut() {
		return (CaptureInvokeItemResult) GetResultObject();
	}

	public CaptureInvokeItem(String url) {
		url = url + "&isself=1&" + APIConfiguration.getCustIdAndToken();
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		CaptureInvokeItemResult result = new CaptureInvokeItemResult();
		try {
			JSONObject json = new JSONObject(responseBody);
			result.status = json.optInt("status");
			result.msg = json.optString("msg");
			JSONObject jsonObject = json.optJSONObject("data");
			if (jsonObject != null) {
				result.body = jsonObject;
				result.controller = jsonObject.optString("controller");
			}
		} catch (JSONException e) {
			e.printStackTrace();
			return result;
		}
		return result;
	}
}
